import os
import shutil
count = 0

def moveFiles(path, disdir):  # path为原始路径，disdir是移动的目标目录

    dirlist = os.listdir(path)
    for i in dirlist:
        child = os.path.join('%s/%s' % (path, i))
        if os.path.isfile(child):
            imagename, jpg = os.path.splitext(i)  # 分开文件名和后缀
            shutil.copy(child, os.path.join(disdir, imagename + ".jpg"))
            # 复制后改为原来图片名称
            # 也可以用shutil.move()
            continue
        moveFiles(child, disdir)


if __name__ == '__main__':
    data = []
    with open("D:/sort.txt","r") as f:  #sort.txt文件位置
        for line in f.readlines():
            line = line.strip("\n")
            line = line.split()
            data.append(line)
        a=[x[0] for x in data]
    for i in a:
        rootimage = i  # 原始图片文件父目录
        # print(rootimage)
        disdir = 'E:/aaa'  # 移动到目标文件夹

        moveFiles(rootimage, disdir)
